package com.example.xxcjgl.ui.components.student

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.example.xxcjgl.data.models.Student

@Composable
fun StudentDialog(
    students: List<Student>,
    onDismiss: () -> Unit,
    onStudentSelected: (Student) -> Unit,
    modifier: Modifier = Modifier
) {
    AlertDialog(
        onDismissRequest = onDismiss,
        title = { Text("选择学生") },
        text = {
            LazyColumn(modifier = modifier.heightIn(max = 400.dp)) {
                if (students.isEmpty()) {
                    item {
                        Text(
                            text = "暂无学生数据",
                            modifier = Modifier
                                .fillMaxWidth()
                                .padding(16.dp),
                            textAlign = TextAlign.Center
                        )
                    }
                } else {
                    items(students) { student ->
                        StudentCard(
                            student = student,
                            onClick = { onStudentSelected(student) },
                            modifier = Modifier.padding(vertical = 4.dp)
                        )
                    }
                }
            }
        },
        confirmButton = {
            TextButton(onClick = onDismiss) {
                Text("取消")
            }
        }
    )
}